#include "MyUtil.h" 

CCArray* MyUtil::vector2CCArray(const vector<CCObject*> vec){
  CCArray *arr = CCArray::create();
  for(int i=0; i<vec.size(); i++){
    arr->addObject(vec.at(i));
  }
  return arr;
}

set<string> MyUtil::getFrameNamesFromPlist(const char* plistname){
  set<string> spriteNames;
  const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plistname);
  CCDictionary *dict = CCDictionary::createWithContentsOfFile(path);
  CCDictionary *frames = (CCDictionary*)dict->objectForKey("frames");
  CCArray *keys = frames->allKeys();
  for(int i=0; i<keys->count(); i++){
    const char * key = ((CCString*)keys->objectAtIndex(i))->getCString();
    CCLog("key %s", key);
    spriteNames.insert(key);
  }
  return spriteNames;
}

vector<CCSpriteFrame*> MyUtil::getSpriteFramesFromPlist(const char* plistname){
  CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistname);
  set<string> spriteNames = parserPlist(plistname);
  if(spriteNames.empty()){
    return vector<CCSpriteFrame*>();
  }
  vector<CCSpriteFrame*> arr;
  set<string>::iterator it = spriteNames.begin();
  for(; it!=spriteNames.end(); ++it){
    string name = (*it).c_str();
    CCLog("key %s", name.c_str());
    CCSpriteFrame *sf = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name.c_str());
    arr.push_back(sf);
  }
  return arr;
}

CCAction* MyUtil::createActionFromPlist(const char* plistname){

} 
